let CacheStort = uni.getStorageSync('stortList') || JSON.stringify([{
	title: "美传自营店",
	id: 1,
}, ])
let stortList = JSON.parse(CacheStort)
console.log(stortList);
export default {
	// 命名空间。
	namespaced: true,
	state: {
		// 获取存储的信息
		Info: uni.getStorageSync('Info') || {}, //设置用户信息
		token: uni.getStorageSync('token') || '', //token
		storeId: uni.getStorageSync('storeId') || 1, //自营店铺地址为 1
		goodsForm: {}, //下单时商品数据
		checkOAddress: {}, //地址
		storeForm: stortList || [], //当前用户登录的店铺.默认显示自营店
	},

	mutations: {
		// 设置用户信息
		setUserInfo(state, data) {
			uni.setStorageSync('Info', data)
			state.Info = data;
		},

		// 设置token
		setToken(state, data) {
			uni.setStorageSync('token', data)
			state.token = data;
		},

		// 保存店铺信息
		setStoreId(state, data) {
			uni.setStorageSync('storeId', data)
			state.storeId = data;
		},

		// 保存下单时的商品数据
		setGoodsList(state, data) {
			state.goodsForm = data;
		},

		//保存的地址数据
		setCAddress(state, data) {
			console.log("add success");
			state.checkOAddress = data;
		},

		//删除保存的地址数据
		setDelAddress(state) {
			console.log("delete success");
			state.checkOAddress = {};
		},

		// 移除登录信息
		setRemove(state) {
			uni.clearStorageSync('Info')
			uni.clearStorageSync('token')
			uni.clearStorageSync('stortList')
			state.Info = {};
			state.token = '';
			let stortList = JSON.stringify([{
				title: "美传自营店",
				id: 1,
			}])

			uni.setStorageSync('stortList', stortList)
			state.storeForm = JSON.parse(stortList)
		},

		// 当前用户登录的店铺
		setStoreForm(state, data) {
			console.log(data);
			state.storeForm = data;
			uni.setStorageSync('stortList', JSON.stringify(data))
		},

	},

	actions: {},
	getters: {
		getType(state) {
			return state.token
		}
	}
}